package com.css.fxfzaqbz.modules.data.service.impl;

import com.css.fxfzaqbz.constants.YNEnum;
import com.css.fxfzaqbz.modules.data.entity.DisposeSubtitle;
import com.css.fxfzaqbz.modules.data.repository.DisposeSubtitleRepository;
import com.css.fxfzaqbz.modules.data.service.DisposeSubtitleService;
import com.css.fxfzaqbz.modules.supergraph.exception.CustomException;
import com.css.fxfzaqbz.util.PlatformDateUtils;
import com.css.fxfzaqbz.util.PlatformSessionUtils;
import com.css.fxfzaqbz.util.UUIDGenerator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class DisposeSubtitleServiceImpl implements DisposeSubtitleService {
    @Resource
    private DisposeSubtitleRepository disposeSubtitleRepository;
    @Override
    public void saveDisposeSubtitle(DisposeSubtitle disposeSubtitle) {
        List<DisposeSubtitle> subtitles = disposeSubtitleRepository.getBySubtitle(disposeSubtitle.getSubtitle());
        if (subtitles.size()!=0){
            throw new CustomException("该子标签已存在,请勿重复添加");
        }
        disposeSubtitle.setId(UUIDGenerator.getUUID());
        disposeSubtitle.setDelFlag(YNEnum.N.toString());
        disposeSubtitle.setCreateUser(PlatformSessionUtils.getUserId());
        disposeSubtitle.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
        disposeSubtitleRepository.saveDisposeSubtitle(disposeSubtitle);
    }

    @Override
    public void delDisposeSubtitle(List<String> ids) {
        disposeSubtitleRepository.delDisposeSubtitle(ids);
    }

    @Override
    public Map<String, Object> getDisposeAllSubtitle(Integer curPage, Integer pageSize,DisposeSubtitle disposeSubtitle) {
        return disposeSubtitleRepository.getDisposeAllSubtitle(curPage,pageSize,disposeSubtitle);
    }
}
